import type { CrudSchema } from '@/hooks/web/useCrudSchemas'
import { dateFormatter } from '@/utils/formatTime'
const { t } = useI18n() // 国际化

// 表单校验
export const rules = reactive({
  mail: [
    { required: true, message: t('profile.rules.mail'), trigger: 'blur' },
    {
      type: 'email',
      message: t('profile.rules.truemail'),
      trigger: ['blur', 'change']
    }
  ],
  username: [required],
  password: [required],
  host: [required],
  port: [required],
  sslEnable: [required],
  starttlsEnable: [required]
})

const crudSchemas = reactive<CrudSchema[]>([
  {
    label: '用户',
    field: 'mail'
  },
  {
    label: '行业',
    field: 'industry'
  },
  {
    label: '点赞',
    field: 'likeNum'
  },
  {
    label: '评论',
    field: 'commentNum'
  },
  {
    label: '收藏',
    field: 'collectNum'
  },
  {
    label: '分享',
    field: 'shareNum'
  },
  {
    label: '抓取时间',
    field: 'grabTime',
    isForm: true,
    formatter: dateFormatter,
    detail: {
      dateFormat: 'YYYY-MM-DD HH:mm:ss'
    }
  },
  {
    label: '发布时间',
    field: 'releaseTime',
    isForm: false,
    formatter: dateFormatter,
    detail: {
      dateFormat: 'YYYY-MM-DD HH:mm:ss'
    }
  }
])
export const { allSchemas } = useCrudSchemas(crudSchemas)
